package db

import (
	"fmt"
	"github.com/go-redis/redis"
	"server/config"
)

var (
	REDIS *redis.Client
)

func InitRedis(redisCfg config.Redis) {
	client := redis.NewClient(&redis.Options{
		Addr:     redisCfg.Addr,
		Password: redisCfg.Password, // no password set
		DB:       redisCfg.DB,       // use default DB
	})
	pong, err := client.Ping().Result()
	if err != nil {
		fmt.Printf("redis connect ping failed, err is %v\n:", err)
	} else {
		fmt.Printf("redis connect ping response %v\n", pong)
		REDIS = client
	}
}
